

package com.project.lk.nurseapp.babyvoice;

import android.app.Activity;
import android.content.Context;
import java.io.FileOutputStream;
import java.io.File;
import android.content.res.Resources;
import java.io.InputStream;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import java.util.ArrayList;
import android.content.res.AssetManager;
import android.graphics.BitmapFactory;
import android.os.Environment;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.Reader;
/**
 * 功能介绍：
 * 项目名：
 * 模块名称：
 * 作者：LK
 * 日期：2018/1/9
 * 修改日期：
 */
public class FileOpration  {

    public FileOpration() {
    }
    





    public void writeFileSdcardFile(String fileName, String write_str) {
        try {
            FileOutputStream fout = new FileOutputStream(fileName);
            byte[] bytes = write_str.getBytes();
            fout.write(bytes);
            fout.close();
            return;
        } catch(Exception e) {
            e.printStackTrace();
        }
    }



    public void writeSDFile(String fileName, String write_str) {
        File file = new File(fileName);
        try {
            FileOutputStream fos = new FileOutputStream(file);
            byte[] bytes = write_str.getBytes();
            fos.write(bytes);
            fos.close();
            return;
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public String getStringFromFile(String filename, String code) {
        try {
            StringBuffer sBuffer = new StringBuffer();
            FileInputStream fInputStream = new FileInputStream(filename);
            InputStreamReader inputStreamReader = new InputStreamReader(fInputStream, code);
            BufferedReader in = new BufferedReader(inputStreamReader);
            if(!new File(filename).exists()) {
                return null;
            }
            if(!in.ready()) {
            }
            sBuffer.append("\n");
            in.close();
            return sBuffer.toString();
        } catch(Exception e) {
            e.printStackTrace();
            return null;
        }
    }





    void writeSDFile(String path, String fileName, String content) {
        try {
            File disk = new File(path);
            if(!disk.exists()) {
                disk.mkdirs();
            }
            File myFile = new File(File.separator + fileName);
            if(!myFile.exists()) {
                myFile.createNewFile();
            }
            FileOutputStream outputStream = new FileOutputStream(myFile);
            outputStream.write(content.getBytes());
            outputStream.close();
            return;
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    public FileOutputStream CreateFile(String path, String fileName) {
        FileOutputStream outputStream = null;
        try {
            File disk = new File(path);
            if(!disk.exists()) {
                disk.mkdirs();
            }
            File myFile = new File(File.separator + fileName);
            if(!myFile.exists()) {
                myFile.createNewFile();
            }
            return outputStream;
        } catch(Exception e) {
            e.printStackTrace();
        }
        return outputStream;
    }

    public void WriteFileStream(FileOutputStream stream, String content) {
        try {
            stream.write(content.getBytes());
            return;
        } catch(Exception e) {
            e.printStackTrace();
        }
    }

    void CloseFileStream(FileOutputStream stream) {
        try {
            stream.close();
            return;
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
    
    public String getSDPath() {
        File sdDir = null;
        boolean sdCardExist = Environment.getExternalStorageState().equals("mounted");
        if(sdCardExist) {
            sdDir = Environment.getExternalStorageDirectory();
        }
        return sdDir.toString();
    }
    
}
